package com.timber.util;

import java.text.*;
import javax.swing.*;
import javax.swing.table.DefaultTableCellRenderer;


public class DateTimeRenderer extends DefaultTableCellRenderer
{
  protected static SimpleDateFormat sdf = new SimpleDateFormat( "dd-MMM-yy hh:mm:ss: z" );
  protected int alignment;


  public DateTimeRenderer()
  {
    this( SwingConstants.CENTER );
  }

  public DateTimeRenderer( int alignment )
  {
    this.alignment = alignment;
  }

  protected void setValue( Object value )
  {
    if( value != null && value instanceof java.util.Date )
    {
      String dateStr = sdf.format( ( java.util.Date )value );
      setText( dateStr );
    }
    else
    {
      super.setValue( value );
    }

    setHorizontalAlignment( alignment );
  }
}
